import time

from com.arcfox.base.base_spider import BaseSpider
from com.arcfox.util import util


class YiQingBaseSpider(BaseSpider):

    def __init__(self):
        super().__init__()
        self.cur_timestamp = str(int(time.time()))

    def get_headers(self):
        return {
            'Connection': 'keep-alive',
            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'x-wif-nonce': 'QkjjtiLM2dCratiA',
            'x-wif-signature': self.get_signature(self.cur_timestamp),
            'x-wif-timestamp': self.cur_timestamp,
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36',
            'x-wif-paasid': 'smt-application',
            'Content-Type': 'application/json; charset=UTF-8',
            'Origin': 'http://bmfw.www.gov.cn',
            'Referer': 'http://bmfw.www.gov.cn/',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        }

    def get_base_params(self, cur_timestamp):
        token = '23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA'
        nonce = '123456789abcdefg'
        passid = 'zdww'
        return {
            "appId": 'NcApplication',
            "paasHeader": passid,
            "timestampHeader": cur_timestamp,
            "nonceHeader": nonce,
            "signatureHeader": util.encrypt_by_sha256(cur_timestamp + token + nonce + cur_timestamp).upper()

        }

    def get_signature(self, cur_timestamp):
        return util.encrypt_by_sha256(
            cur_timestamp + 'fTN2pfuisxTavbTuYVSsNJHetwq5bJvC' + 'QkjjtiLM2dCratiA' + cur_timestamp).upper()
